package com.lxmes.hr.controller;

import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lxmes.common.annotation.Log;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.common.enums.BusinessType;
import com.lxmes.hr.domain.NcAttendRg;
import com.lxmes.hr.service.INcAttendRgService;
import com.lxmes.common.utils.poi.ExcelUtil;
import com.lxmes.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 人工考勤Controller
 *
 * @author ruoyi
 * @date 2023-02-13
 */
@RestController
@RequestMapping("/hr/rgAttend")
public class NcAttendRgController extends BaseController
{
    @Autowired
    private INcAttendRgService ncAttendRgService;

    /**
     * 查询人工考勤列表
     */
    @PreAuthorize("@ss.hasPermi('hr:rgAttend:list')")
    @GetMapping("/list")
    public TableDataInfo list(NcAttendRg ncAttendRg)
    {
        startPage();
        List<NcAttendRg> list = ncAttendRgService.selectNcAttendRgList(ncAttendRg);
        return getDataTable(list);
    }

    /**
     * 导出人工考勤列表
     */
    @PreAuthorize("@ss.hasPermi('hr:rgAttend:export')")
    @Log(title = "人工考勤", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NcAttendRg ncAttendRg)
    {
        List<NcAttendRg> list = ncAttendRgService.selectNcAttendRgList(ncAttendRg);
        ExcelUtil<NcAttendRg> util = new ExcelUtil<NcAttendRg>(NcAttendRg.class);
        util.exportExcel(response, list, "人工考勤数据");
    }

    /**
     * 获取人工考勤详细信息
     */
    @PreAuthorize("@ss.hasPermi('hr:rgAttend:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ncAttendRgService.selectNcAttendRgById(id));
    }

    /**
     * 新增人工考勤
     */
    @PreAuthorize("@ss.hasPermi('hr:rgAttend:add')")
    @Log(title = "人工考勤", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NcAttendRg ncAttendRg)
    {
        return toAjax(ncAttendRgService.insertNcAttendRg(ncAttendRg));
    }

    /**
     * 修改人工考勤
     */
    @PreAuthorize("@ss.hasPermi('hr:rgAttend:edit')")
    @Log(title = "人工考勤", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NcAttendRg ncAttendRg)
    {
        return toAjax(ncAttendRgService.updateNcAttendRg(ncAttendRg));
    }

    /**
     * 修改人工考勤
     */
    @PreAuthorize("@ss.hasPermi('hr:rgAttend:edit')")
    @Log(title = "人工考勤", businessType = BusinessType.UPDATE)
    @PutMapping("/editById")
    public AjaxResult editById(@RequestBody NcAttendRg ncAttendRg)
    {
        return toAjax(ncAttendRgService.updateNcAttendRgById(ncAttendRg));
    }

    /**
     * 删除人工考勤
     */
    @PreAuthorize("@ss.hasPermi('hr:rgAttend:remove')")
    @Log(title = "人工考勤", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ncAttendRgService.deleteNcAttendRgByIds(ids));
    }


    /**
     * 删除人工考勤
     */
    @PreAuthorize("@ss.hasPermi('hr:rgAttend:remove')")
    @Log(title = "人工考勤", businessType = BusinessType.DELETE)
    @DeleteMapping("/deleteNcAttendRgByIdentyCode/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(ncAttendRgService.deleteNcAttendRgByIdentyCode(ids));
    }

    /**
     * 导入人工考勤
     */
    @Log(title = "人工考勤", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<NcAttendRg> util = new ExcelUtil<>(NcAttendRg.class);
        List<NcAttendRg> ncAttendRgList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = ncAttendRgService.imporIteminfo(ncAttendRgList, updateSupport, operName);
        return AjaxResult.success(message);
    }
    // 下载模板
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) throws IOException
    {
        ExcelUtil<NcAttendRg> util = new ExcelUtil<>(NcAttendRg.class);
        util.importTemplateExcel(response,"人工考勤");
    }
}
